﻿using Autodesk.AutoCAD.Colors;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _02创建图形
{
    public class HatchExam
    {
        [CommandMethod("HatchDemo")]
        public void HatchDemo()
        {

            //图案填充
            #region
            //Database db = HostApplicationServices.WorkingDatabase;

            //ObjectId cId = db.AddCircleModelSpace(new Point3d(100, 100, 0), 100);
            //#region
            ////ObjectIdCollection obIds = new ObjectIdCollection();
            ////obIds.Add(cId);
            ////using (Transaction trans = db.TransactionManager.StartTransaction())
            ////{
            ////    //声明图案填充对象
            ////    Hatch hatch = new Hatch();
            ////    //设置填充比例
            ////    hatch.PatternScale = 5;
            ////    //设置填充类型和图案名
            ////    hatch.SetHatchPattern(HatchPatternType.PreDefined, "ANGLE");
            ////    //加入图形数据库
            ////    BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
            ////    BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
            ////    btr.AppendEntity(hatch);
            ////    trans.AddNewlyCreatedDBObject(hatch, true);

            ////    //设置填充角度
            ////    hatch.PatternAngle = Math.PI / 4;
            ////    //设置关联
            ////    hatch.Associative = true;
            ////    //设置边界图形和填充方式
            ////    hatch.AppendLoop(HatchLoopTypes.Outermost, obIds);
            ////    //计算填充并显示
            ////    hatch.EvaluateHatch(true);
            ////    //提交事务
            ////    trans.Commit();
            ////}
            //#endregion

            //db.HatchEnity(HatchTool.HatchPatternName.arb88,4,45 ,cId);
            //ObjectId cId1 = db.AddCircleModelSpace(new Point3d(300, 100, 0), 100);
            //db.HatchEnity(HatchTool.HatchPatternName.arbrstd, 2, 0, Color.FromColorIndex(ColorMethod.ByColor, 2), 1, cId1);

            //ObjectId c1 = db.AddCircleModelSpace(new Point3d(500, 500, 0), 200);
            //ObjectId c2 = db.AddCircleModelSpace(new Point3d(500, 500, 0), 100);
            //List<HatchLoopTypes> loopTypes = new List<HatchLoopTypes>();
            //loopTypes.Add(HatchLoopTypes.Outermost);
            //loopTypes.Add(HatchLoopTypes.Outermost);
            //db.HatchEnity(loopTypes, HatchTool.HatchPatternName.arconc, 0.2, 0,c1,c2);

            //c1 = db.AddCircleModelSpace(new Point3d(1000, 500, 0), 200);
            //c2 = db.AddCircleModelSpace(new Point3d(1000, 500, 0), 100);
            //ObjectId c3 = db.AddCircleModelSpace(new Point3d(1000, 500, 0), 50);
            //loopTypes.Add(HatchLoopTypes.Outermost);
            //db.HatchEnity(loopTypes, HatchTool.HatchPatternName.arbrstd, 0.2, 0, c1, c2,c3);

            //c1 = db.AddCircleModelSpace(new Point3d(1500, 500, 0), 200);
            //c2 = db.AddCircleModelSpace(new Point3d(1500, 500, 0), 100);
            //c3 = db.AddCircleModelSpace(new Point3d(1500, 500, 0), 50);

            //db.HatchEnity(loopTypes, HatchTool.HatchPatternName.arbrstd, 0.2, 0, c1);
            #endregion

            //渐变填充

            Database db = HostApplicationServices.WorkingDatabase;
            short colorIndex1 = 1;
            short colorIndex2 = 2;
            ObjectIdCollection objIds = new ObjectIdCollection();
            objIds.Add(db.AddCircleModelSpace(new Point3d(100,100,0),100));
            string hatchGradientName = HatchTool.HatchGradientName.gr_invcylinder;
            db.HatchGradient(2, 6, HatchTool.HatchGradientName.gr_hemisperical, db.AddRectToModelSpace(new Point2d(100, 100), new Point2d(500, 300)));
        }


    }
}
